package com.yang.newCustomersTransferBackProcess.dao;

import com.yang.newCustomersTransferBackProcess.pojo.Adviser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface AdviserDao extends JpaRepository<Adviser, Integer>, JpaSpecificationExecutor<Adviser> {

    @Query(value = "select * from adviser a where a.team_id in (select left(a.team_id, length(a.team_id)-2) from adviser a where a.id = ?1) and a.role_id = ?2", nativeQuery = true)
    Adviser findSuperior(int adviserId, int roleId);

    @Query(value = "select * from adviser a where a.team_id in (select left(a.team_id, length(a.team_id)-?2) from adviser a where a.id = ?1)", nativeQuery = true)
    Adviser findLeader(int adviserId, int digit);
}
